// pages/appointment_detail/index.js
const app     = getApp()
const request = require('../../utils/request.js');
const config = require('../../utils/config.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        topBarHeight: 64,
        id:0,
        detail:null
    },
    getBarInfo(e) {
        this.setData({
            topBarHeight: e.detail.topBarHeight
        })
    },
    goupdate()
    {
        var that =this;
        console.log(that.data.detail)
        wx.navigateTo({
            url: '/pages/select_time/index?hosptial_id='+that.data.detail.hisptial_id+'&appoints_id='+that.data.id,
          })
    },
    cancelpoint(e){
        var that = this;
        var json = {};
        json.id=that.data.id;
         wx.showModal({
           title: '提示',
           content: '是否取消？',
           complete: (res) => {
             if (res.cancel) {
               
             }
         
             if (res.confirm) {
                request.requestLoading(
                    "/api/appoint/cancelpoint",
                    json,
                    'POST',
                  ).then((res) => {
                    if(res.code==1){
                       that.init_Data()
                    }else{
                        wx.showToast({
                          title: res.msg,
                          icon:'none'
                        })
                    }
                   
                   
              
                  }).catch((err) => {
                    console.error(err);
                  });
             }
           }
         })
      },
    openmap(e){
        
        var mdata =this.data.detail.hospital;
        console.log(mdata)
        if(mdata){
            var address=mdata.province+mdata.city+mdata.area+mdata.address;
      
            wx.openLocation({
      
              latitude:Number(mdata.lat),
              
              longitude: Number(mdata.lng),
              
              name: mdata.hospital_name,
              
              address: address,
              
              scale: 18,
              
              success: function(res) {
              
              console.log(res)
              
              },
              
              fail: function(err) {
              
              console.log(err)
              
              }
              
              })
              
              
       
        }
        },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
       this.setData({
           id:options.id
       })
       this.getDetail();
    },
    getDetail()
    {
        var that = this;
        var json = {};
        json.id = that.data.id;
        request.requestLoading(
            "/api/appoint/appointDetail",
            json,
            'GET',
        ).then((res) => {
            console.log(res)

            if(res.data){
                that.setData({
                  detail:res.data
                });


            }
           

        }).catch((err) => {
            console.error(err);
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        this.getDetail()
        setTimeout(function(){
          wx.stopPullDownRefresh();
        },500)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

   
})